<?php

namespace App\Library\Service;

use App\Library\Logic\AmountLogic;
use App\Library\Logic\SalesRecordLogic;
use App\Library\Requests\SalesRecord\SalesRecordPageRequest;
use Illuminate\Http\JsonResponse;

class SalesRecordService
{
    /**
     *
     * @return SalesRecordLogic
     *
     */
    private function logic(): SalesRecordLogic
    {
        if (empty($this->logic)) $this->logic = new SalesRecordLogic;
        return $this->logic;
    }

    public function paging(SalesRecordPageRequest $request): JsonResponse
    {
        $creditedAmount = $this->logic()->creditedAmount();
        return success($this->logic()->paging($request));
    }

    public function tj(): JsonResponse
    {
        $creditedAmount = $this->logic()->creditedAmount();

        return success([
            'balance' => AmountLogic::balance(),
            'withdraw' => (new AmountLogic)->withdraw(),
            'credited_amount' => $creditedAmount->credited_amount
        ]);
    }
}
